home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- * TextStyleUtils.c - utilties for dealing with styled TextEdit
- *
- *
- * © 1998, Graham Cox
- *
- *
- *
- *************************************************************************************************/
-
- #include "TextStyleUtils.h"
-
-
- void TEGetStyleRunInfo( TEStyleRunInfo* runInfo, TEHandle te )
- {
- if ( te == NULL || runInfo == NULL )
- return;
-
- // initialise fields of record:
-
- runInfo->fr = 0;
- runInfo->runStyles = 0;
- runInfo->contStyles = 0xFF;
- runInfo->numSizes = 0;
- runInfo->numFonts = 0;
-
- // get the run start and finish:
-
- short st, en, lh, as;
- TextStyle ts;
-
- st = (*te)->selStart;
- en = (*te)->selEnd;
-
- // we're going to go through from start to end getting the text style of every character
-
- do
- {
- TEGetStyle( st, &ts, &lh, &as, te );
-
- // use our own flag if plain style
-
- if ( ts.tsFace == 0 )
- ts.tsFace = kPlainStyle;
-
- // for the face, we just need to OR what we got with what we already have.
- // to set the continuity flag, just clear it if the face bit is 0.
-
- runInfo->runStyles |= ts.tsFace;
- runInfo->contStyles &= ts.tsFace;
-
- // for the font and size, we need to do more:
-
- if ( ! FontInRun( ts.tsFont, runInfo, &as ))
- runInfo->fonts[ runInfo->numFonts++ ] = ts.tsFont;
-
- if ( ! SizeInRun( ts.tsSize, runInfo, &as ))
- runInfo->sizes[ runInfo->numSizes++ ] = ts.tsSize;
- }
- while( ++st < en );
-
- // finally set the flags for continous font and size. These are true if the
- // corresponding count is 0 or 1.
-
- if ( runInfo->numFonts < 2 )
- runInfo->fr |= kFontIsContinuous;
-
- if ( runInfo->numSizes < 2 )
- runInfo->fr |= kSizeIsContinuous;
- }
-
-
- Boolean FontInRun( short aFont, TEStyleRunInfo* runInfo, short* index )
- {
- // check whether the given font is in the run or not
-
- short i;
-
- if ( runInfo->numFonts >= MAX_FONTS )
- return TRUE;
-
- for ( i = 0; i < runInfo->numFonts; i++ )
- {
- if ( runInfo->fonts[i] == aFont )
- {
- *index = i;
- return TRUE;
- }
- }
-
- *index = runInfo->numFonts;
- return FALSE;
- }
-
-
- Boolean SizeInRun( short aSize, TEStyleRunInfo* runInfo, short* index )
- {
- // check whether the given size is in the run or not
-
- short i;
-
- if ( runInfo->numSizes >= MAX_SIZES )
- return TRUE;
-
- for ( i = 0; i < runInfo->numSizes; i++ )
- {
- if ( runInfo->sizes[i] == aSize )
- {
- *index = i;
- return TRUE;
- }
- }
-
- *index = runInfo->numSizes;
- return FALSE;
- }
-